package com.ap.core.domain;

import javax.persistence.Embeddable;
import java.io.Serializable;


/**
 * Specific type representing an account number.
 */
@Embeddable
public final class AccountNumber implements Serializable{

    /** String value of the account number *. */
    private String accountNumber;

    /**
     * private constructor which creates an <code>AccountNumber</code> using a supplied string representation of an account number.
     * 
     * @param accountNumber the account number
     */
    private AccountNumber(String accountNumber) {

        this.accountNumber = accountNumber;
    }

    /**
     * Protected no arg for JPA.
     */
    protected AccountNumber() {
    }

    /**
     * Method to return an account number.
     * 
     * @param accountNumber the account number
     * 
     * @return AccountNumber
     */
    public static AccountNumber valueOf(String accountNumber) {

        return new AccountNumber(accountNumber);
    }

    

    @Override
    public int hashCode() {
        return accountNumber.hashCode();
    }

    /**
     * 
     * {@inheritDoc}
     * 
     */
    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }    
        AccountNumber comparison = (AccountNumber) o;
        return accountNumber.equals(comparison.accountNumber);
    }


    @Override
    public String toString() {
        return accountNumber;
    }

}
